﻿using System.Collections.Generic;
using System.Linq;
using HqlIntellisense.ConfigurationAbstraction;

namespace HQLAddin.ConfigurationInspector
{
	public static class ConfigurationHelper
	{
		public static IEnumerable<IPersistentClassInformation> CombineClassInformation(
			IEnumerable<IPersistentClassInformation> currentClasses,
			IEnumerable<IPersistentClassInformation> newClasses)
		{
			var classesToInclude = newClasses.Where(ci => !currentClasses.Any(c => c.ClassName == ci.ClassName)).ToArray();
			return currentClasses.Union(classesToInclude).ToArray();
		}

		public static IDictionary<string, string> CombineImports(
			IDictionary<string, string> currentImports, 
			IDictionary<string, string> newImports)
		{
			var result = currentImports;
			foreach (var import in newImports.Where(import => !result.ContainsKey(import.Key)))
			{
				result[import.Key] = import.Value;
			}
			return result;
		}
	}
}